package me.xinping.libs.recording

import android.app.Service
import android.content.Intent
import android.os.Binder
import android.os.IBinder

/**
 * 录音的后台服务.
 * <p>
 * Date 2018/12/5
 * @author fanxinping_cd@keruyun.com
 */
class RecorderService : Service() {
    private val binder: IBinder = RecorderBinder()

    override fun onBind(intent: Intent?): IBinder = binder

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        return Service.START_STICKY
    }

    override fun onDestroy() {
        super.onDestroy()
        RecorderManager.instance.stopRecording()
    }

    fun startRecord(filePath: String, listener: RecorderManager.OnRecordingListener) {
        RecorderManager.instance.startRecording(filePath, listener)
    }

    fun stopRecording() {
        RecorderManager.instance.stopRecording()
    }

    inner class RecorderBinder : Binder() {
        fun service(): RecorderService = this@RecorderService
    }

}